{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:     Started server process [1444]\n",
      "INFO:     Waiting for application startup.\n",
      "INFO:     Application startup complete.\n",
      "INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n",
      "INFO:     127.0.0.1:18510 - \"GET /hello?hello=hello HTTP/1.1\" 200 OK\n"
     ]
    }
   ],
   "source": [
    "# 响应字符串\n",
    "from fastapi import FastAPI\n",
    "from fastapi.responses import PlainTextResponse, Response\n",
    "import uvicorn\n",
    "\n",
    "app = FastAPI()\n",
    "\n",
    "@app.get('/info', response_class=PlainTextResponse)\n",
    "async def info():\n",
    "    print('info')\n",
    "    return 'info'\n",
    "\n",
    "@app.get('/hello')\n",
    "async def hello(hello: str):\n",
    "    print(hello)\n",
    "    return Response(content=hello)\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    config = uvicorn.Config(app=app, host='127.0.0.1', port=8000)\n",
    "    server = uvicorn.Server(config)\n",
    "    await server.serve()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
